package com.lw.ipad;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author LW
 * @2020/9/12 9:37
 */
//测试ip
public class TestInetAddress {

    public static void main(String[] args) {
        try {
            InetAddress localhost = InetAddress.getByName("localhost");
            System.out.println(localhost);//localhost/127.0.0.1
            InetAddress inetName1 = InetAddress.getLocalHost();
            System.out.println(inetName1);//DESKTOP-IOF5VIA/10.254.3.102
            //查询网址ip地址
            InetAddress inetName2 = InetAddress.getByName("www.alibaba.com");
            System.out.println(inetName2);//www.alibaba.com/203.119.129.109

            System.out.println(inetName2.getCanonicalHostName());//规范的名字
            System.out.println(inetName2.getHostAddress());//ip
            System.out.println(inetName2.getHostName());//域名

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }
}
